package jpath

import (
	"gitee.com/tiger000/taishan_web/jpath/tokenizers"
	"sync"
)

var jPool sync.Map

func Parse(data string) (*JExpress, error) {
	if value, ok := jPool.Load(data); ok {
		return value.(*JExpress), nil
	}
	charStream := tokenizers.NewCharStream(data)
	token := tokenizers.NewTokenizer(*charStream)
	parser := NewParser(token)

	jExp, err := parser.Parse()
	if err != nil {
		return nil, err
	}
	jExp.SourceCode = data
	jPool.Store(data, jExp)
	return jExp, nil
}
